package com.bysj.sausys.activiti.listener;

import com.bysj.sausys.common.UserConst;
import com.bysj.sausys.model.SysUser;
import com.bysj.sausys.service.ISysUserService;
import com.bysj.sausys.util.SpringContextUtil;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 获取所有的团委管理员监听器
 *
 * @author WangZK
 */
public class SysCylTaskListener implements TaskListener {

    @Override
    public void notify(DelegateTask delegateTask) {
        ISysUserService sysUserService = SpringContextUtil.getBean("sysUserService");
        //查询所有的团委管理员
        List<SysUser> list = sysUserService.findByCategoryId(UserConst.TUANWEIGUANLIYUAN);
        List<String> names = new ArrayList<>();
        if (list.size() > 0) {
            for (SysUser sysUser : list) {
                names.add(sysUser.getUsername());
            }
        }

        delegateTask.addCandidateUsers(names);
    }
}
